Skip to content

Conversation

@kkim-labelbox
Copy link
Contributor

Background

Currently, the only way to group video segments in SDK's VideoObjectAnnotations is to have an instance for every consecutive frame. This PR introduces a concept of segment_index, a new attribute in Video annotation classes, that can group annotation instances together into a video segment, without having to be consecutive frames.

How does segment_index work?

  • segment_index must be present in every VideoObjectAnnotation or VideoClassificationAnnotation. If only some annotations contain segment_index, error is raised
  • If none of the annotations contain segment_index, segments are evaluated using consecutive frames, same as the original logic
  • Every annotation belonging to the same segment_index will be grouped within the same video segment

Heads up

  • Both serialization and deserialization are updated. User can deserialize NDJson with multiple keyframes in a segment into VideoObjectAnnotations, which will automatically assign segment_index. User can also serialize VideoObjectAnnotations with segment_index, which will properly evaluate frames within the same segment. I updated the test cases to test this
  • VideoClassificationAnnotations is not affected by this change much, because classification answer change using VideoClassificationAnnotations seems to not be supported. Will tackle this in another ticket

# Group segment by consecutive frames, since `segment_index` is not present
return cls._get_consecutive_frames(
sorted([annotation.frame for annotation in annotation_group]))
elif len(sorted_frame_segment_indices) == len(annotation_group):
Copy link
Contributor

@jtsodapop jtsodapop Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question been a while since i have reviewed annotation_group, could you explain why this check is == len(annotation_group) ? Is it because we expect the number of segments to be the number of items in the annotation group?

Copy link
Contributor Author

@kkim-labelbox kkim-labelbox Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! So this is just checking that every annotation inside annotation_group contains a segment_index.

segment_index must be present in every VideoObjectAnnotation or VideoClassificationAnnotation. If only some annotations contain segment_index, error is raised

segment_groups = defaultdict(list)
for frame, segment_index in sorted_frame_segment_indices:
if segment_index < last_segment_id:
raise ValueError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question In what instances do we expect this error to occur, since we are fetching indices via enumerate and then sorting? Should we ever expect this to be a problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be an issue if users construct their own Video annotations, and accidentally assign segment_indices in a non-ascending order

def to_common(self, name: str, feature_schema_id: Cuid):
result = []
for segment in self.segments:
for idx, segment in enumerate(self.segments):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment This is a really neat idea :)

for group in segment_groups.values():
frame_ranges.append((group[0], group[-1]))
return frame_ranges
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question When would we expect only partial indices to occur?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If users are providing their own Video annotation objects!

@kkim-labelbox kkim-labelbox merged commit e5770fd into develop Jul 19, 2022
@jtsodapop jtsodapop deleted the kkim/AL-2896 branch September 14, 2022 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants